package com.charonmc.utils;

import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.Objects;

public class BungeeCordChatUtils {
    public static void sendACMessage(ProxiedPlayer fromPlayer, String msg) {
        for (ProxiedPlayer x : ProxyServer.getInstance().getPlayers()) {
            if (x.hasPermission("Core.AdminChat") && !Objects.equals(x.getServer().getInfo().getName(), "login")) {
                x.sendMessage(new ComponentBuilder("§c§l[AdminChat]" + "§b§l"+ fromPlayer.getName() + "§a§l> §c§l" + msg).create());
            }
        }
    }

    public static void sendSCMessage(ProxiedPlayer fromPlayer,String msg) {
        for (ProxiedPlayer x: ProxyServer.getInstance().getPlayers() ) {
            if (x.hasPermission("Core.StaffChat") && !Objects.equals(x.getServer().getInfo().getName(), "login")) {
                x.sendMessage(new ComponentBuilder("§e§l[StaffChat]" + "§b§l"+ fromPlayer.getName() + "§a§l> §e§l" + msg).create());
            }
        }
    }

    public static void sendBCMessage(ProxiedPlayer fromPlayer,String msg) {
        for (ProxiedPlayer x: ProxyServer.getInstance().getPlayers()) {
            if (x.hasPermission("Core.BuilderChat") && !Objects.equals(x.getServer().getInfo().getName(), "login")) {
                x.sendMessage(new ComponentBuilder("§5§l[BuilderChat]" + "§b§l"+ fromPlayer.getName() + "§a§l> §5§l" + msg).create());
            }
        }
    }

    public static void sendACMessage(String msg) {
        for (ProxiedPlayer x : ProxyServer.getInstance().getPlayers()) {
            if (x.hasPermission("Core.AdminChat")) {
                x.sendMessage(new ComponentBuilder("§cAdminChat§a >" + "§bConsole：" + "§c" + msg).create());
            }
        }
    }

    public static void sendSCMessage(String msg) {
        for (ProxiedPlayer x: ProxyServer.getInstance().getPlayers()) {
            if (x.hasPermission("Core.StaffChat")) {
                x.sendMessage(new ComponentBuilder("§eAdminChat§a >" + "§bConsole：" + "§e" + msg).create());
            }
        }
    }

    public static void sendBCMessage(String msg) {
        for (ProxiedPlayer x: ProxyServer.getInstance().getPlayers()) {
            if (x.hasPermission("Core.BuilderChat")) {
                x.sendMessage(new ComponentBuilder("§5AdminChat§a >" + "§bConsole：" +  "§5" + msg).create());
            }
        }
    }
}
